package jmine.tec.security.impl.export;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import jmine.tec.services.api.export.DefaultExportAction;
import jmine.tec.services.api.export.EntityExporter;
import jmine.tec.services.api.export.ExporterKey;
import jmine.tec.services.api.export.ReferenceMap;
import jmine.tec.services.io.ServiceBean;
import bancosys.tec.security.impl.dao.CredentialDAO;
import bancosys.tec.security.impl.dao.MetaCredentialDAO;

/**
 * Exportador que extrai todo o conteúdo de credenciais e metacredenciais do sistema.
 * 
 * @author lundberg
 */
public class AllCredentialsExporter implements EntityExporter<AllCredentials> {

    private MetaCredentialDAO metaCredentialDAO;

    private CredentialDAO credentialDAO;

    /**
     * {@inheritDoc}
     */
    public List<ServiceBean> export(ReferenceMap referenceMap, AllCredentials entity) {
        return Collections.emptyList();
    }

    /**
     * {@inheritDoc}
     */
    public List<Object> exportBefore(AllCredentials entity) {
        return Collections.emptyList();
    }

    /**
     * {@inheritDoc}
     */
    public List<Object> exportAfter(AllCredentials entity) {
        List<Object> entities = new ArrayList<Object>();
        entities.addAll(this.metaCredentialDAO.findAllPostscriptCredentials());
        entities.addAll(this.credentialDAO.findAllPostscriptCredentials());
        return entities;
    }

    /**
     * {@inheritDoc}
     */
    public ExporterKey getExporterKey() {
        return new ExporterKey(DefaultExportAction.INCLUIR, AllCredentials.class);
    }

    /**
     * @param metaCredentialDAO the metaCredentialDAO to set
     */
    public void setMetaCredentialDAO(MetaCredentialDAO metaCredentialDAO) {
        this.metaCredentialDAO = metaCredentialDAO;
    }

    /**
     * @param credentialDAO the credentialDAO to set
     */
    public void setCredentialDAO(CredentialDAO credentialDAO) {
        this.credentialDAO = credentialDAO;
    }
}
